<?php
 session_start();
 require_once "conn.php";
 
 //echo $_GET[vrnum]," - ",$_GET[vrop]," - ",$_GET[btn],"<br />";
 
 //save selected answer
 if (!empty($_GET["vrop"])) {
  $_SESSION["questions"]["a"][$_GET["vrnum"]] = $_GET["vrop"];
 } 
 
 //update number
 if (!empty($_GET["vrop"])) {
  if ($_GET["btn"] == 'next')
   $_GET["vrnum"] < 10 ? $_GET["vrnum"]++ : $_GET["vrnum"] = 1;
  else if ($_GET["btn"] == 'prev')
   $_GET["vrnum"] > 1 ? $_GET["vrnum"]-- : $_GET["vrnum"] = 10;  
 }
 
 $vrnum = $_GET["vrnum"];
 //get random question from database
 mysql_query("SET CHARACTER SET utf8");
 $vrsql = mysql_query("SELECT * FROM tbquiz WHERE id = '".$_SESSION["questions"]["q"][$_GET["vrnum"]]."'") or die(mysql_eerno().': '.mysql_error());
 while($vrdata = mysql_fetch_array($vrsql))
 {
  echo "<form name=\"frmquiz\" method=\"get\">";
  echo "$_GET[vrnum] ) $vrdata[question]<br />";
  echo 
   "a) <input type=\"radio\" name=\"op\" value=\"a\""; 
   if (!empty($_SESSION["questions"]["a"][$vrnum])){
    if ($_SESSION["questions"]["a"][$vrnum] == "a") echo "checked";
   }
  echo " />$vrdata[a]<br />";

  echo
   "b) <input type=\"radio\" name=\"op\" value=\"b\"";
   if (!empty($_SESSION["questions"]["a"][$vrnum])){
    if ($_SESSION["questions"]["a"][$vrnum] == "b") echo "checked";
   }
  echo " />$vrdata[b]<br />";
  
  echo
   "c) <input type=\"radio\" name=\"op\" value=\"c\"";
   if (!empty($_SESSION["questions"]["a"][$vrnum])){
    if ($_SESSION["questions"]["a"][$vrnum] == "c") echo "checked";
   }
  echo " />$vrdata[c]<br />";
   
  echo
   "d) <input type=\"radio\" name=\"op\" value=\"d\"";
   if (!empty($_SESSION["questions"]["a"][$vrnum])){
    if ($_SESSION["questions"]["a"][$vrnum] == "d") echo "checked";
   }
  echo " />$vrdata[d]<br />";
   
  echo
   "e) <input type=\"radio\" name=\"op\" value=\"e\"";
   if (!empty($_SESSION["questions"]["a"][$vrnum])){
    if ($_SESSION["questions"]["a"][$vrnum] == "e") echo "checked";
   }
  echo " />$vrdata[e]<br />";
 ?>
  
  <input type="button" name="btnprev" onclick="javascript:loadXML('divpanel','src/p_form.php?','vrop='+getradio(this.form,this.elements)+'&vrnum=<?php echo $vrnum;?>&btn=prev');" value="anterior" />
  <input type="button" name="btnnext" onclick="javascript:loadXML('divpanel','src/p_form.php?','vrop='+getradio(this.form,this.elements)+'&vrnum=<?php echo $vrnum;?>&btn=next');" value="proxima" /><br />
  <br />
  <input type="button" name="btnfinish" value="finalizar" onclick="javascript:loadXML('divpanel','src/p_rel.php?','$vrnum=<?php echo $vrnum ?>')" />
 <?php
  echo "</form>";
  }
?>
